function [IndLists, RGB] = segmentCellsAndLDs(NC,LD,nmodel,cmodel,lmodel,imSize,imSize0)

% nSubsets = 100;

model = nmodel;
% F = pcImageFeatures(NC,model.sigmas,model.offsets,model.osSigma,model.radii,model.cfSigma,model.logSigmas,model.sfSigmas,[],[]);
% [~,ncPM] = imClassify(F,model.treeBag,nSubsets);
[~,ncPM] = pixelClassifierClassify(NC,model);

model = cmodel;
% F = pcImageFeatures(NC,model.sigmas,model.offsets,model.osSigma,model.radii,model.cfSigma,model.logSigmas,model.sfSigmas,[],[]);
% [~,clPM] = imClassify(F,model.treeBag,nSubsets);
[~,clPM] = pixelClassifierClassify(NC,model);

[M,~,~,N,~,~,~] = nucAndCellPM2CellMask(ncPM,clPM);
% MN3 = cat(3,double(M),cat(3,double(N),zeros(size(N))));
s = regionprops(M,'Area','Eccentricity');
M = bwpropfilt(M,'Eccentricity',[0 0.95]);
areas = cat(1,s.Area);

if isempty(areas)
    RGB1 = repmat(imadjust(NC),[1 1 3]);
    RGB2 = repmat(imadjust(LD),[1 1 3]);
    RGB3 = zeros(size(RGB2));
    RGB = [RGB1 RGB2 RGB3];
    IndLists = {};
    return
end

M = bwareafilt(M,[prctile(areas,1) prctile(areas,99)]);

M0 = M;
R = imadjust(NC);
G = R;
B = R;
N = bwmorph(N,'remove');
M = bwmorph(M,'remove');
R(N) = 0; G(N) = 0; B(N) = 1;
R(M) = 1; G(M) = 0; B(M) = 0;


model = lmodel;
% F = pcImageFeatures(LD,model.sigmas,model.offsets,model.osSigma,model.radii,model.cfSigma,model.logSigmas,model.sfSigmas,[],[]);
% [imL,~] = imClassify(F,model.treeBag,nSubsets);
[imL,~] = pixelClassifierClassify(LD,model);
L = imL == 1;

L0 = L;
L = bwmorph(L,'remove');
R(L) = 0; G(L) = 1; B(M) = 0;
RGB1 = cat(3,R,cat(3,G,B));
R = imadjust(LD);
G = R;
B = R;
R(L) = 0; G(L) = 1; B(L) = 0;
RGB2 = cat(3,R,cat(3,G,B));

[IndLists, RGB3] = nucAndLDMasksToIndLists(M0,L0,imSize0);
RGB3 = imresize(RGB3,imSize);
RGB = [RGB1 RGB2 RGB3];
% RGB = [ncPM clPM MN3 RGB1 RGB2 RGB3];

end